package com.ruoyi.ucar.service.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ucar.boreq.CheXinMengApiQueryBoReq;
import com.ruoyi.ucar.boreq.CheXinMengGetReportBoReq;
import com.ruoyi.ucar.boreq.LemonApiQueryBoReq;
import com.ruoyi.ucar.boreq.LemonGetReportBoReq;
import com.ruoyi.ucar.boresp.*;
import com.ruoyi.ucar.common.CommonCheXinMengBoResp;
import com.ruoyi.ucar.common.CommonLemonBoResp;
import com.ruoyi.ucar.config.CarApiQueryConfig;
import com.ruoyi.ucar.service.ISysFileMainService;
import com.ruoyi.ucar.service.UCarQueryApiService;
import com.ruoyi.ucar.util.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.SortedMap;
import java.util.TreeMap;

@Service
public class UCarQueryApiServiceImpl implements UCarQueryApiService {
    @Autowired
    CarApiQueryConfig carApiQueryConfig;

    @Autowired

    private ISysFileMainService sysFileMainService;

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public CommonCheXinMengBoResp cheXinMengCustomerAuthApiQuery() {
        ObsImageBoResp obsImageBoRes=  sysFileMainService.obsDownloadImageToBase64String("241023af-b528-49de-9f18-e816f5dc3ef8");

        CommonCheXinMengBoResp commonCheXinMengBoResp=new CommonCheXinMengBoResp();
        SortedMap<Object, Object> sortedMap   = new TreeMap<Object, Object>() {
                {
                    put("UserName","王强");
                    put("IDNumber", "342501199009277650");
                    put("CompanyName","芜湖咖博网络科技有限公司");
                    put("BusinessLicenseNumber", "91340200MA2T38064Q");
                    put("Base64SignImg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCACOAOwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD6oooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKzNa17S9DtxPq19b2kR+6ZHwW+g6n8KANOigHIyOlFABRSUUALRXIS/8JzOzKj+H7JedrBZZyfwO0CrvgXVr7WNHmm1Nbfzorqa3EtuC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");
                    put("Base64LicenseImg", obsImageBoRes.getBase64String());

                }
            };


        String dateTime=DateUtils.dateTimeNow();
        String sign= CommonUtil.cheXinMengCreateSign(dateTime,carApiQueryConfig.getCheXinMengAppKey(),carApiQueryConfig.getCheXinMengAppSecret());
        HttpResponse res =HttpRequest.
                post(carApiQueryConfig.getCheXinMengApiUrl()+"/Service/CustomerAuthService.ashx?Method=Save&"
                        +"app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign)
                .body(JSONUtil.toJsonStr(sortedMap)).execute();


        if(res.getStatus()==200){
            String resultJson=res.body();
            commonCheXinMengBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonCheXinMengBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            commonCheXinMengBoResp.setErrorCode(JSONUtil.parseObj(resultJson).getStr("ErrorCode"));
            if(commonCheXinMengBoResp.getResult()==1){
                CheXinMengApiQueryBoResp cheXinMengApiQueryBoRes=new CheXinMengApiQueryBoResp();
                cheXinMengApiQueryBoRes.setOrderID(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("OrderID"));
                cheXinMengApiQueryBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportUrl"));
                commonCheXinMengBoResp.setReturnObj(cheXinMengApiQueryBoRes);
            }
        }else{
            commonCheXinMengBoResp.setResult(res.getStatus());
            commonCheXinMengBoResp.setMessage("车信盟车辆查询失败！");
        }
        return commonCheXinMengBoResp;
    }



    @Override
    public CommonCheXinMengBoResp cheXinMengApiQuery(CheXinMengApiQueryBoReq cheXinMengApiQueryBoReq) {
            CommonCheXinMengBoResp commonCheXinMengBoResp=new CommonCheXinMengBoResp();
        SortedMap<Object, Object> sortedMap;
        if(cheXinMengApiQueryBoReq.getImageType()==0) {
             sortedMap = new TreeMap<Object, Object>() {
                {
                    put("vincode", cheXinMengApiQueryBoReq.getVinCode());
                    put("imagetype", cheXinMengApiQueryBoReq.getImageType());
                    put("drivinglicenceimage", cheXinMengApiQueryBoReq.getDrivingLicenceImage());
                }
            };
        }else{
            sortedMap = new TreeMap<Object, Object>() {
                {
                    put("vincode", cheXinMengApiQueryBoReq.getVinCode());
                    put("imagetype", cheXinMengApiQueryBoReq.getImageType());
                    put("registrationcertificateimage", cheXinMengApiQueryBoReq.getRegistrationcertificateImage());
                }
            };
        }
        if(StringUtils.isNotEmpty(cheXinMengApiQueryBoReq.getSignImgage()))
        {
            sortedMap.put("signimgage", cheXinMengApiQueryBoReq.getSignImgage());
        }

        String dateTime=DateUtils.dateTimeNow();
        String sign= CommonUtil.cheXinMengCreateSign(dateTime,carApiQueryConfig.getCheXinMengAppKey(),carApiQueryConfig.getCheXinMengAppSecret());
        HttpResponse res =HttpRequest.
                    post(carApiQueryConfig.getCheXinMengApiUrl()+cheXinMengApiQueryBoReq.getServiceUrl()
                            +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode())
                    .body(JSONUtil.toJsonStr(sortedMap)).execute();
        logger.info("车信盟查询请求地址：{}",carApiQueryConfig.getCheXinMengApiUrl()+cheXinMengApiQueryBoReq.getServiceUrl()
                +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode());
        logger.info("车信盟查询请求参数：{}",sortedMap);
        logger.info("车信盟查询响应结果：{}",res);

        if(res.getStatus()==200){
            String resultJson=res.body();
            commonCheXinMengBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonCheXinMengBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            commonCheXinMengBoResp.setErrorCode(JSONUtil.parseObj(resultJson).getStr("ErrorCode"));
            if(commonCheXinMengBoResp.getResult()==1){
                CheXinMengApiQueryBoResp cheXinMengApiQueryBoRes=new CheXinMengApiQueryBoResp();
                cheXinMengApiQueryBoRes.setOrderID(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("OrderID"));
                cheXinMengApiQueryBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportUrl"));
                commonCheXinMengBoResp.setReturnObj(cheXinMengApiQueryBoRes);
            }
        }else{
            commonCheXinMengBoResp.setResult(res.getStatus());
            commonCheXinMengBoResp.setMessage("车信盟车辆查询失败！");
        }
            return commonCheXinMengBoResp;
    }

    @Override
    public CommonCheXinMengBoResp cheXinMengGetReport(CheXinMengGetReportBoReq cheXinMengGetReportBoReq) {
        CommonCheXinMengBoResp commonCheXinMengBoResp=new CommonCheXinMengBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign= CommonUtil.cheXinMengCreateSign(dateTime,carApiQueryConfig.getCheXinMengAppKey(),carApiQueryConfig.getCheXinMengAppSecret());
        HttpResponse res =HttpRequest.
                get(carApiQueryConfig.getCheXinMengApiUrl()+"/Service/ReportService.ashx"
                        +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode()+"&OrderID="+cheXinMengGetReportBoReq.getOrderId())
                .execute();
        logger.info("车信盟查询请求地址2：{}",carApiQueryConfig.getCheXinMengApiUrl()+"/Service/ReportService.ashx"
                +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode()+"&OrderID="+cheXinMengGetReportBoReq.getOrderId());
        logger.info("车信盟查询响应结果2：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonCheXinMengBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonCheXinMengBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            commonCheXinMengBoResp.setErrorCode(JSONUtil.parseObj(resultJson).getStr("ErrorCode"));
            if(commonCheXinMengBoResp.getResult()==1){
                CheXinMengGetReportBoResp cheXinMengGetReportBoRes=new CheXinMengGetReportBoResp();
                cheXinMengGetReportBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportUrl"));
                commonCheXinMengBoResp.setReturnObj(cheXinMengGetReportBoRes);
            }
        }else{
            commonCheXinMengBoResp.setResult(res.getStatus());
            commonCheXinMengBoResp.setMessage("车信盟获取报告查询失败！");
        }
        return commonCheXinMengBoResp;
    }

    @Override
    public CommonCheXinMengBoResp cheXinMengGetImageReport(CheXinMengGetReportBoReq cheXinMengGetReportBoReq) {
        CommonCheXinMengBoResp commonCheXinMengBoResp=new CommonCheXinMengBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign= CommonUtil.cheXinMengCreateSign(dateTime,carApiQueryConfig.getCheXinMengAppKey(),carApiQueryConfig.getCheXinMengAppSecret());
        HttpResponse res =HttpRequest.
                get(carApiQueryConfig.getCheXinMengApiUrl()+"/Service/ImgReportService.ashx"
                        +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode()+"&OrderID="+cheXinMengGetReportBoReq.getOrderId()
                +"&just_url=1")
                .execute();
        logger.info("车信盟查询请求地址3：{}",carApiQueryConfig.getCheXinMengApiUrl()+"/Service/ImgReportService.ashx"
                +"?app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign+"&auth_code="+carApiQueryConfig.getCheXinMengAllyCode()+"&OrderID="+cheXinMengGetReportBoReq.getOrderId()
                +"&just_url=1");
        logger.info("车信盟查询响应结果3：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonCheXinMengBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonCheXinMengBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            commonCheXinMengBoResp.setErrorCode(JSONUtil.parseObj(resultJson).getStr("ErrorCode"));
            if(commonCheXinMengBoResp.getResult()==1){
                CheXinMengGetImageReportBoResp cheXinMengGetImageReportBoRes=new CheXinMengGetImageReportBoResp();
                cheXinMengGetImageReportBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportUrl"));
                cheXinMengGetImageReportBoRes.setReportBase64(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportBase64"));
                commonCheXinMengBoResp.setReturnObj(cheXinMengGetImageReportBoRes);
            }
        }else{
            commonCheXinMengBoResp.setResult(res.getStatus());
            commonCheXinMengBoResp.setMessage("车信盟获取图片报告查询失败！");
        }
        return commonCheXinMengBoResp;
    }

    @Override
    public CommonCheXinMengBoResp cheXinMengGetBalance() {
        CommonCheXinMengBoResp commonCheXinMengBoResp=new CommonCheXinMengBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign= CommonUtil.cheXinMengCreateSign(dateTime,carApiQueryConfig.getCheXinMengAppKey(),carApiQueryConfig.getCheXinMengAppSecret());
        HttpResponse res =HttpRequest.
                get(carApiQueryConfig.getCheXinMengApiUrl()+"/Service/CustomerService.ashx"
                        +"?Method=GetBalance&app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign)
                .execute();
        logger.info("车信盟查询请求地址4：{}",carApiQueryConfig.getCheXinMengApiUrl()+"/Service/CustomerService.ashx"
                +"?Method=GetBalance&app_key="+carApiQueryConfig.getCheXinMengAppKey()+"&timestamp="+dateTime+"&sign="+sign);
        logger.info("车信盟查询响应结果4：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonCheXinMengBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonCheXinMengBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            commonCheXinMengBoResp.setErrorCode(JSONUtil.parseObj(resultJson).getStr("ErrorCode"));
            if(commonCheXinMengBoResp.getResult()==1){
                CheXinMengGetBalanceBoResp cheXinMengGetBalanceBoRes=new CheXinMengGetBalanceBoResp();
                cheXinMengGetBalanceBoRes.setBalance(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getBigDecimal("Balance"));

                commonCheXinMengBoResp.setReturnObj(cheXinMengGetBalanceBoRes);
            }
        }else{
            commonCheXinMengBoResp.setResult(res.getStatus());
            commonCheXinMengBoResp.setMessage("车信盟查询余额失败！");
        }
        return commonCheXinMengBoResp;
    }

    @Override
    public CommonLemonBoResp lemonCarApiQuery(LemonApiQueryBoReq lemonApiQueryBoReq) {
        CommonLemonBoResp commonLemonBoResp=new CommonLemonBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign=CommonUtil.lemonGenerateSign(carApiQueryConfig.getLemonAppKey(),lemonApiQueryBoReq.getVin(),dateTime,carApiQueryConfig.getLemonAppSecret()).toUpperCase();
        SortedMap<Object, Object>  sortedMap = new TreeMap<Object, Object>() {
                {
                    put("appkey", carApiQueryConfig.getLemonAppKey());
                    put("timestamp", dateTime);
                    put("sign",sign);
                    put("vin",lemonApiQueryBoReq.getVin());
                    put("imgVehicleLicense", lemonApiQueryBoReq.getImgVehicleLicense());
                    put("imageType", lemonApiQueryBoReq.getImageType());
                    if(StringUtils.isNotEmpty(lemonApiQueryBoReq.getOwnerName())) {
                        put("ownerName", lemonApiQueryBoReq.getOwnerName());
                    }
                }
            };
        HttpResponse res =HttpRequest.
                post(carApiQueryConfig.getLemonApiUrl()+"?method=QueryReport")
                .body(JSONUtil.toJsonStr(sortedMap)).execute();
        logger.info("柠檬查询请求地址：{}", carApiQueryConfig.getLemonApiUrl()+"?method=QueryReport");
        logger.info("柠檬查询请求参数：{}",sortedMap);
        logger.info("柠檬查询响应结果：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonLemonBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonLemonBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
             if(commonLemonBoResp.getResult()==1){
                 LemonApiQueryBoResp lemonApiQueryBoRes=new LemonApiQueryBoResp();
                 lemonApiQueryBoRes.setOrderID(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("OrderId"));
                 lemonApiQueryBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getJSONObject("ReturnObj").getStr("ReportUrl"));
                 commonLemonBoResp.setReturnObj(lemonApiQueryBoRes);
            }
        }else{
            commonLemonBoResp.setResult(res.getStatus());
            commonLemonBoResp.setMessage("柠檬车辆车况查询失败！");
        }
        return commonLemonBoResp;
    }

    @Override
    public CommonLemonBoResp lemonGetReport(LemonGetReportBoReq lemonGetReportBoReq) {
        CommonLemonBoResp commonLemonBoResp=new CommonLemonBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign=CommonUtil.lemonGenerateSign2(carApiQueryConfig.getLemonAppKey(),dateTime,carApiQueryConfig.getLemonAppSecret()).toUpperCase();
        HttpResponse res =HttpRequest.
                get(carApiQueryConfig.getLemonApiUrl()+"?method=GetReportUrl"+"&orderId="+lemonGetReportBoReq.getOrderId()
                +"&sign="+sign+"&appKey="+carApiQueryConfig.getLemonAppKey()+"&timestamp="+dateTime)
                .execute();
        logger.info("柠檬查询请求地址2：{}", carApiQueryConfig.getLemonApiUrl()+"?method=GetReportUrl"+"&orderId="+lemonGetReportBoReq.getOrderId()
                +"&sign="+sign+"&appKey="+carApiQueryConfig.getLemonAppKey()+"&timestamp="+dateTime);
         logger.info("柠檬查询响应结果2：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonLemonBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonLemonBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
            if(commonLemonBoResp.getResult()==1){
                LemonGetReportBoResp lemonGetReportBoRes=new LemonGetReportBoResp();
                lemonGetReportBoRes.setReportUrl(JSONUtil.parseObj(resultJson).getStr("ReturnObj"));
                commonLemonBoResp.setReturnObj(lemonGetReportBoRes);
            }
        }else{
            commonLemonBoResp.setResult(res.getStatus());
            commonLemonBoResp.setMessage("柠檬车辆报告查询失败！");
        }
        return commonLemonBoResp;
    }

    @Override
    public CommonLemonBoResp lemonGetBalance() {
        CommonLemonBoResp commonLemonBoResp=new CommonLemonBoResp();
        String dateTime=DateUtils.dateTimeNow();
        String sign=CommonUtil.lemonGenerateSign2(carApiQueryConfig.getLemonAppKey(),dateTime,carApiQueryConfig.getLemonAppSecret()).toUpperCase();
        HttpResponse res =HttpRequest.
                get(carApiQueryConfig.getLemonApiUrl()+"?method=GetBalance"
                        +"&sign="+sign+"&appKey="+carApiQueryConfig.getLemonAppKey()+"&timestamp="+dateTime)
                .execute();
        logger.info("柠檬查询请求地址3：{}",
                carApiQueryConfig.getLemonApiUrl()+"?method=GetBalance"
                        +"&sign="+sign+"&appKey="+carApiQueryConfig.getLemonAppKey()+"&timestamp="+dateTime);
        logger.info("柠檬查询响应结果3：{}",res);
        if(res.getStatus()==200){
            String resultJson=res.body();
            commonLemonBoResp.setResult(JSONUtil.parseObj(resultJson).getInt("Result"));
            commonLemonBoResp.setMessage(JSONUtil.parseObj(resultJson).getStr("Message"));
             if(commonLemonBoResp.getResult()==1){
                 LemonGetBalanceBoResp lemonGetBalanceBoRes=new LemonGetBalanceBoResp();
                 lemonGetBalanceBoRes.setBalance(JSONUtil.parseObj(resultJson).getBigDecimal("ReturnObj"));
                 commonLemonBoResp.setReturnObj(lemonGetBalanceBoRes);
            }
        }else{
            commonLemonBoResp.setResult(res.getStatus());
            commonLemonBoResp.setMessage("柠檬查询余额失败！");
        }
        return commonLemonBoResp;
    }


    @Override
    public void applyCustomerAuth() {

    }
}
